package com.ruoyi.business.ledger.controller;

import com.ruoyi.business.ledger.domain.RealCard;
import com.ruoyi.business.ledger.service.IRealCardService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 台账列表Controller
 *
 * @author lcy
 * @date 2024-09-24
 */
@RestController
@RequestMapping("/ledger/realCard")
@Api(tags = "实物卡片相关接口")
public class RealCardController extends BaseController {

    @Autowired
    private IRealCardService realCardService;

    /**
     * 查询台账列表
     */
    @RequiresPermissions("ledger:realCard:list")
    @GetMapping("/list")
    @Log(value = "查询台账列表")
    @ApiOperation("查询实物卡片列表")
    public TableDataInfo list(RealCard realCard) {
        startPage();
        List<RealCard> list = realCardService.selectRealCardList(realCard);
        return getDataTable(list);
    }

    /**
     * 导出台账列表
     */
    @RequiresPermissions("ledger:realCard:export")
    @Log(title = "台账列表", businessType = BusinessType.EXPORT,value = "导出台账列表")
    @PostMapping("/export")
    @ApiOperation("导出实物卡片列表")
    public void export(HttpServletResponse response, RealCard realCard) {
        List<RealCard> list = realCardService.selectRealCardList(realCard);
        ExcelUtil<RealCard> util = new ExcelUtil<RealCard>(RealCard.class);
        util.exportExcel(response, list, "台账列表数据");
    }

    /**
     * 获取台账列表详细信息
     */
    @RequiresPermissions("ledger:realCard:query")
    @GetMapping(value = "/{id}")
    @Log(value = "获取台账列表详细信息")
    @ApiOperation("获取实物卡片详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(realCardService.selectRealCardById(id));
    }

    /**
     * 新增台账列表信息
     */
    @RequiresPermissions("ledger:realCard:add")
    @Log(title = "台账列表", businessType = BusinessType.INSERT,value = "新增台账列表")
    @PostMapping("/insert")
    @ApiOperation("新增实物卡片")
    public AjaxResult add(@RequestBody RealCard realCard) {
        return toAjax(realCardService.insertRealCard(realCard));
    }

    /**
     * 修改台账列表信息
     */
    @RequiresPermissions("ledger:realCard:edit")
    @Log(title = "台账列表", businessType = BusinessType.UPDATE,value = "修改台账列表")
    @PutMapping("/update")
    @ApiOperation("修改实物卡片")
    public AjaxResult edit(@RequestBody RealCard realCard) {
        return toAjax(realCardService.updateRealCard(realCard));
    }

    /**
     * 删除台账列表信息
     */
    @RequiresPermissions("ledger:realCard:remove")
    @Log(title = "台账列表", businessType = BusinessType.DELETE,value = "删除台账列表")
	@DeleteMapping("/delete/{ids}")
    @ApiOperation("删除实物卡片信息")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(realCardService.deleteRealCardByIds(ids));
    }
}
